.PYTHONY: run help build admin

# 定义编译后的文件名
APP_NAME = backend-framework-template
# 定义编译后的版本号
APP_VERSION = 1.0.0

run: ## 直接运行Go程序
	@go run main.go

build: ## 编译Go程序
	@echo "开始编译主程..."
	@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o dist/$(APP_NAME)-linux-amd64-$(APP_VERSION) main.go
	@echo "\033[32m编译主程完成\e[0m"
	@echo "开始编译后台管理系统..."
	@. ${HOME}/.nvm/nvm.sh && cd admin_vue && nvm use 20 && npm run build
	@echo "\033[32m编译后台管理系统完成\e[0m"

build-win: ## 编译到Windows系统下进行运行
	@echo "开始编译主程..."
	@CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc go build -ldflags "-s -w" -o dist/$(APP_NAME)-windows-amd64-$(APP_VERSION).exe main.go
	@echo "\033[32m编译主程完成\e[0m"
	@echo "开始编译后台管理系统..."
	@. ${HOME}/.nvm/nvm.sh && cd admin_vue && nvm use 20 && npm run build
	@echo "\033[32m编译后台管理系统完成\e[0m"

admin: ## 运行后台管理系统
	@echo "开始编译后台管理系统..."
	@. ${HOME}/.nvm/nvm.sh && cd admin_vue && nvm use 20 && npm run dev

help: ## 输出帮助信息
	@echo "后台编译框架的Make模板文件"
	@echo
	@echo "Usage:"
	@echo "  make <target>"
	@echo
	@echo "Targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-15s\033[0m %s\n", $$1, $$2}'